import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import index from '../component/index.vue'
import detail from '../component/detail.vue'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: index
  },
  {
    path: '/detail',
    name: 'detail',
    component: detail
  }
]


// const router = new VueRouter({ routes })
// export default router


/* 
这里为什么不导出一个router实例
每次用户请求都需要创建 router实例
*/

export default function createRouter() {
  return new Router({
    mode: 'history',
    routes
  })
}

